package handle;

import common.Result;
import dataBean.UserDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import service.TokenService;
import service.UserService;

/**
 * Created by lxl on 2015/11/3.
 */
@Controller
@RequestMapping("ssms/login")
public class LoginHandle {

    @Autowired
    private TokenService tokenService ;

    @Autowired
    private UserService userService ;

    @RequestMapping(method = RequestMethod.POST)
    public @ResponseBody
    Result process( @RequestBody UserDo userDo){

        Result result = userService.login(userDo) ;

        if( result.isSucces() ){

            tokenService.toToken(userDo.getUsername()) ;

        }

        return result ;

    }

}
